<?php
// NOTE!
// This is quick and dirty code! It comes without error handling!

// Timeout in seconds waiting for a response.
$timeout = 10;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
//socket_bind($sock,"0.0.0.0",12345);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
$buf = "Hello World";
socket_sendto($sock, $buf, strlen($buf), 0, "255.255.255.255", 12345);
socket_set_block($sock);
socket_set_option($sock,
                         SOL_SOCKET,
                         SO_RCVTIMEO,
                         array("sec"=>10,"usec"=>0));
$timeout += time();
while (time() <= $timeout-1) {
 if (($len = @socket_recvfrom($sock,$ret,2048,0,$cIP,$cPort)) != false) {
  echo bin2hex($ret);
 }
}
socket_set_nonblock($sock);
socket_close($sock);
?>
